package com.example.demo.start;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

public class SocketClient {

	public static void main(String[] args) {
		int port = 9999;
		InetAddress inetAddress;
		Socket socket = null;
		OutputStream clientVaule = null;
		try {
			inetAddress = InetAddress.getByName("127.0.0.1");
			socket = new Socket(inetAddress, port);
			clientVaule = socket.getOutputStream();
			clientVaule.write("测试测试".getBytes());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			if (socket != null) {
				try {
					socket.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			
			if ( clientVaule !=null) {
				try {
					clientVaule.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}
